<#include "../common/layout/__mainlayout.html">
<#include "../common/__pagination.html">

<#assign pageBreadCrumbs>
    <li class="active"><a href="#">基础配置</a></li>
    <li class="active">模板管理</li>
</#assign>

<#assign pageCss>
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css" />
    <link rel="stylesheet" href="${ctx}/static/admin/assets/css/chosen.css" />
    <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css" />
</#assign>
<#assign pageJavascript>

    <script type="text/javascript">
        $(document).ready(function() {


            if (!ace.vars['touch']) {
                $('.chosen-select').chosen({allow_single_deselect: true});
            }

            $("#editModal").on("hidden.bs.modal", function () {
                $(this).removeData("bs.modal");
            });

            // 删除按钮
            $("a.delete").on(ace.click_event, function (e) {
                var currentA = this;
                e.preventDefault();
//                bootbox.setDefaults({locale:"zh_CN"});
                bootbox.confirm({
                            message: "确定删除该模板?",
                            buttons: {
                                confirm: {
                                    label: "确定",
                                    className: "btn-primary btn-sm"
                                },
                                cancel: {
                                    label: "取消",
                                    className: "btn-sm"
                                }
                            },
                            callback: function (result) {
                                if (result) {
                                    $.ajax({
                                        type: "POST",
                                        url: $(currentA).attr("href"),
                                        dataType: 'text',
                                        success: function (msg) {
                                            var msg = eval("(" + msg + ")");
                                            if (msg.result == "success") {
                                                window.location = "${refer!}";
                                            } else {
                                                alert(msg.messages);
                                            }
                                        },
                                        error: function () {
                                            bootbox.alert("删除失败");
                                        }
                                    });
                                }
                            }
                        }
                );
            });
        });
    </script>
</#assign>

<@mainlayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript currentMenu="AppConfigFlag-templateFlag">
    <div class="row">
        <div class="col-xs-12">
            <form id="searchForm" action="${ctx}/admin/template/list.html" class="form-search form-inline" method="GET">
                <label class="col-xs-1 text-right">模板名:</label><input type="text" id="templateName"  name="templateName" class="input-sm col-xs-2" value="${query.templateName!}"/>&nbsp;
                <label class="col-xs-1 text-right">模板类型:</label>
              <select class="chosen-select form-control" name="templateType" id="templateType" data-placeholder="Choose a State..." >
                  <option value="">全部</option>
                <#list fieldItems as item>
                    <option value="${item.id!}" <#if item.id?? && query.templateType?? &&item.id==query.templateType>selected </#if>>${item.itemTitle!}</option>
                </#list>
            </select>
                <input type="submit" id="searchBtn" class="btn btn-sm btn-primary" value="查询"/>&nbsp;
                <a href="${ctx}/admin/template/add.html" class="btn btn-sm btn-warning" data-toggle="modal" data-target="#editModal"><i class="ace-icon fa fa-plus"></i>添加</a>

            <table id="contentTable" class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th width="40" align="center" >模板ID</th>
                    <th width="20" align="left" >模板名</th>
                    <th width="20" align="center"> 模板类型</th>
                    <th width="40" align="center" >操作</th>
                </tr>
                </thead>

                <tbody>
                <#list pageList.listData as template>
                    <tr>
                        <td>${template.id!}</td>
                        <td>${template.templateName!}</td>
                        <td>${template.dictFieldItem!}</td>
                        <td>
                            <div class="hidden-sm hidden-xs action-buttons">
                                <a class="green tooltip-success edit" href="${ctx}/admin/template/view.html?id=${template.id!}" data-rel="tooltip" title="编辑" data-toggle="modal" data-target="#editModal"><span class="label label-success">编辑</span></a>
                                <a class="red tooltip-error delete" href="${ctx}/admin/template/delete.do?id=${template.id!}" data-rel="tooltip" title="删除" data="${template.id!}"><span class="label label-danger">删除</span></a>
                            </div>

                            <div class="hidden-md hidden-lg">
                                <div class="inline position-relative">
                                    <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown" data-position="auto">
                                        <i class="ace-icon fa fa-caret-down icon-only bigger-120"></i>
                                    </button>
                                    <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                        <li><a href="${ctx}/admin/template/view.html?id=${template.id!}" class="tooltip-success edit" data-rel="tooltip" title="编辑" data-toggle="modal" data-target="#editModal"> <span class="green"><i class="ace-icon fa fa-pencil-square-o bigger-120"></i></span></a></li>
                                         <li><a href="${ctx}/admin/template/delete.do?id=${template.id!}" class="tooltip-error delete" data-rel="tooltip" title="删除" data="${template.id!}"> <span class="red"><i class="ace-icon fa fa-trash-o bigger-120"></i></span></a></li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                </#list>
                </tbody>
            </table>
        <@pagination pageList!/>
            </form>
        </div>
    </div>

    <div id="editModal" class="modal fade" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 800px;">
            </div>
        </div>
    </div>
</@mainlayout>